IdeaBlade.EntityModel Assembly > IdeaBlade.EntityModel Namespace > EntityListManager<T> Class > EntityListManager<T> Constructor : EntityListManager<T> Constructor(EntityManager,Predicate<T>,EntityProperty[],IList,Boolean) |
'Declaration
Public Function New( _ ByVal entityManager As EntityManager, _ ByVal filter As Predicate(Of T), _ ByVal filterProperties() As EntityProperty, _ ByVal list As IList, _ ByVal shouldRefresh As Boolean _ )
'Usage
Dim entityManager As EntityManager Dim filter As Predicate(Of T) Dim filterProperties() As EntityProperty Dim list As IList Dim shouldRefresh As Boolean Dim instance As New EntityListManager(Of T)(entityManager, filter, filterProperties, list, shouldRefresh)
public EntityListManager<T>( EntityManager entityManager, Predicate<T> filter, EntityProperty[] filterProperties, IList list, bool shouldRefresh )
Performance will be needlessly poor if the EntityListManager tests an entity every time any of its properties change. To avoid this, specify in the constructor or the FilterProperties property which entity properties are relevant to the filtering.
You can choose to have the EntityListManager refresh the list immediately after assuming management of the list. This is unnecessary if the supplied list is known to be complete at the time the manager is initialized.
An EntityListManager holds weak references to the Lists it watches. This means that you will need to hold on to a reference to each ELM to insure that it does not go out of scope and get garbage collected. One approach to this is to use Lists that implement the IdeaBlade.Core.IHasListManager interface. This will insure each list keeps a reference to its ELM and any shared ELM's will not go out of scope until the last of their child lists do.
// Example showing how a List<T> can be managed as a live list. public void EntityListManagerSample() { DomainModelEntityManager mgr = new DomainModelEntityManager(); // Retrieve a customer and employee. var customer = mgr.Customers.FirstOrDefault(c => c.Id == 1); var employee = mgr.Employees.FirstOrDefault(e => e.Id == 1); // Load a List with customer's order summaries. var list = new List<OrderSummary>(customer.OrderSummaries); int orderCount = list.Count; // We want to watch for any new orders for this customer. // We can't "watch" the NavigationEntityProperty, so watch its FK. var prop = OrderSummary.Customer_fk_IdEntityProperty; // Set up the manager. IListManager manager = new EntityListManager<OrderSummary>(mgr, os => os.Customer == customer, // filter new[] { prop }, // watch list, // list to be managed false); // refresh now // Create a new order - the list count should increment. OrderSummary aOrder = mgr.CreateEntity<OrderSummary>(); aOrder.Employee = employee; aOrder.Customer = customer; aOrder.AddToManager(); Assert.IsTrue(list.Count == orderCount + 1); // Now delete this order - the list count should decrement. aOrder.EntityAspect.Delete(); Assert.IsTrue(list.Count == orderCount); }
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2